
import { DatePicker } from 'element-ui';
import CustomPicker from './customPicker.vue'
import Vue from 'vue';
// bugfix elementUi value有值时 如果type由date 变为datetime时会，再去选择时间是会报错，
export default Vue.component('widgetWrap', {
  functional: true,
  render (createElement, context: any) {
    const { value, type, quick } = (context as any).props;
    if (value) {
      if (type === 'dateTime' && value.length === 10) {
        context.props.value = value + ' 00:00:00';
        // 更新父组件里对应的值
        context.data.on.input(context.props.value);
      } else if (type === 'date' && value.length > 10) {
        context.props.value = value.split(' ')[0];
        context.data.on.input(context.props.value);
      }
    }
    const newDate = quick ? CustomPicker : DatePicker;
    return createElement(
      newDate,
      {
        ...context.data, props: context.props
      }
    );
  }
});
